package com.glorysoft.sunnypda.ui.unlock

import android.os.Bundle
import android.widget.CompoundButton
import android.widget.RadioGroup
import com.glorysoft.sunnypda.BR
import com.glorysoft.sunnypda.R
import com.glorysoft.sunnypda.base.BaseActivity
import com.glorysoft.sunnypda.databinding.ActivityUnLockBinding
import com.glorysoft.sunnypda.entity.EqpInfoEntity
import com.glorysoft.sunnypda.entity.ui.ToastMessageBean
import kotlinx.android.synthetic.main.activity_un_lock.*

/**
 * FileName: UnLockActivity
 * Author: XJH
 * Date: 2022/1/7 16:59
 * Description:
 * History:
 */
class UnLockActivity : BaseActivity<UnLockViewModel,ActivityUnLockBinding>() {
    override fun layoutId(): Int {
        return R.layout.activity_un_lock
    }

    override fun initVariableId(): Int {
        return BR.unLockViewModel
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle(getString(R.string.manually_unlock))
        initEdit(etEqpWork,object : EditTextListener{
            override fun onTextChangeListener(s: String) {
                viewModel.getEqpInfo(s)
            }
        })
        setRightListener(getString(R.string.confirm)) {
            if (etEqpWork.text.toString().isEmpty()) {
                viewModel.defUI.toastEvent.value = ToastMessageBean(getString(R.string.eqp_hint), false)
                return@setRightListener
            }

            viewModel.submitLock(rbLock.isChecked,etEqpWork.text.toString())
        }
    }

    override fun initData() {
        viewModel.defUI.callObserve.observe(this){
            if (it.type == 0){
                val eqp: EqpInfoEntity  = it.item as EqpInfoEntity
                rbLock.isChecked = eqp.ISHOLD == 0
                rbUnLock.isChecked = eqp.ISHOLD == 1
            }else{
                viewModel.defUI.toastEvent.value = ToastMessageBean("操作成功!", true)
//                rbLock.isChecked = false
//                rbUnLock.isChecked = false
                etEqpWork.setText("")
            }

        }
    }
}